﻿using System.Collections.Generic;
using System.Security.Cryptography;
using Ibp.Service.Entity.DEntity;
using Ibp.Service.Entity.ODAEntity;
using OdaOperation.DB;
using Teigha.Core;
using Teigha.TD;

namespace OdaOperation.Extends
{
    public static class ExtendCurves
    {
        /// <summary>
        /// 扩展方法：将曲线集合附加到数据库中
        /// </summary>
        /// <param name="database">扩展方法所属的 DbDatabase 对象</param>
        /// <param name="name">新图层的名称</param>
        /// <param name="color">新图层的颜色</param>
        /// <param name="curves">要添加到数据库的曲线集合</param>
        public static void AppendOdDbCurves(this DbDatabase database, string name, string color, IEnumerable<DCurve> curves)
        {
            // 添加新的图层
            database.AddNewLayer(name);

            // 设置图层的属性
            database.SetLayerOfLineSomething(name, null, LineWeight.kLnWtByLwDefault, color);

            // 遍历所有的曲线
            foreach (DCurve curf in curves)
            {
                // 设置曲线所属的图层
                ((DEntityBase)curf).Layer = name;

                // 处理线段
                DLine val = (DLine)(object)((curf is DLine) ? curf : null);
                if (val != null)
                {
                    database.AppendOdDbLine(val);
                }

                // 处理圆弧
                DArc val2 = (DArc)(object)((curf is DArc) ? curf : null);
                if (val2 != null)
                {
                    database.AppendOdDbArc(val2);
                }

                // 处理椭圆
                DEllipse val3 = (DEllipse)(object)((curf is DEllipse) ? curf : null);
                if (val3 != null)
                {
                    database.AppendOdDbEllipse(val3);
                }

                // 处理圆
                DCircle val4 = (DCircle)(object)((curf is DCircle) ? curf : null);
                if (val4 != null)
                {
                    database.AppendOdDbCircle(val4);
                }
            }
        }
    }

}